﻿//==================================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 文件名: wkWorkResult.cs
// 作 者：代码自动生成
// 日 期：2012-11-21 9:39:44
// 描 述：
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00             
//==================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
using Csla;
using lite;
using Csla.Validation;
using Csla.Data;
using System.Data.SqlClient;
using ZX.DAL;
using OpenExpressApp.ORM; 

namespace ZX.EHR.Library
{
	/// <summary>
    /// 
    /// </summary>
	[Serializable]
    [Table(Name="wkWorkResult")]
    [ZX.DBModule.Table("wkWorkResult","ID")]
	public class wkWorkResult: ZX.DBModule.BaseEntity
	{
        
        #region Business Methods 业务方法
       
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< Guid > IDProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< Guid >("ID"));
        [DataObjectField(true, true)]
        [Column, PK]
        public Guid ID
        {
            get { return GetProperty(IDProperty); }
            set { SetProperty(IDProperty, value); }
        }
        
		/// <summary>
        /// 员工ID
        /// </summary>
        private static PropertyInfo< Guid > EmployeeIDProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< Guid >("EmployeeID"));
        [Column]
        public Guid EmployeeID
        {
            get { return GetProperty(EmployeeIDProperty); }
            set { SetProperty(EmployeeIDProperty, value); }
        }
		/// <summary>
        /// 工作日期
        /// </summary>
        private static PropertyInfo< DateTime > WorkDateProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< DateTime >("WorkDate"));
        [Column]
        public DateTime WorkDate
        {
            get { return GetProperty(WorkDateProperty); }
            set { SetProperty(WorkDateProperty, value); }
        }
		/// <summary>
        /// 上班打卡时间
        /// </summary>
        private static PropertyInfo< DateTime > BeginCardDateTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< DateTime >("BeginCardDateTime"));
        [Column]
        public DateTime BeginCardDateTime
        {
            get { return GetProperty(BeginCardDateTimeProperty); }
            set { SetProperty(BeginCardDateTimeProperty, value); }
        }
		/// <summary>
        /// 下班打卡时间
        /// </summary>
        private static PropertyInfo< DateTime > EndCardDateTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< DateTime >("EndCardDateTime"));
        [Column]
        public DateTime EndCardDateTime
        {
            get { return GetProperty(EndCardDateTimeProperty); }
            set { SetProperty(EndCardDateTimeProperty, value); }
        }
		/// <summary>
        /// 班次
        /// </summary>
        private static PropertyInfo< Guid > WorkTimeIDProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< Guid >("WorkTimeID"));
        [Column]
        public Guid WorkTimeID
        {
            get { return GetProperty(WorkTimeIDProperty); }
            set { SetProperty(WorkTimeIDProperty, value); }
        }
		/// <summary>
        /// 考勤结果
        /// </summary>
        private static PropertyInfo< string > WkStatusProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< string >("WkStatus"));
        [Column]
        public string WkStatus
        {
            get { return GetProperty(WkStatusProperty); }
            set { SetProperty(WkStatusProperty, value); }
        }
		/// <summary>
        /// 迟到(单位分钟m)
        /// </summary>
        private static PropertyInfo< int > LateTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< int >("LateTime"));
        [Column]
        public int LateTime
        {
            get { return GetProperty(LateTimeProperty); }
            set { SetProperty(LateTimeProperty, value); }
        }
		/// <summary>
        /// 早退(单位分钟m)
        /// </summary>
        private static PropertyInfo< int > AdvancedTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< int >("AdvancedTime"));
        [Column]
        public int AdvancedTime
        {
            get { return GetProperty(AdvancedTimeProperty); }
            set { SetProperty(AdvancedTimeProperty, value); }
        }
		/// <summary>
        /// 请假时数(单位小时h)
        /// </summary>
        private static PropertyInfo< decimal > LeaveTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("LeaveTime"));
        [Column]
        public decimal LeaveTime
        {
            get { return GetProperty(LeaveTimeProperty); }
            set { SetProperty(LeaveTimeProperty, value); }
        }
		/// <summary>
        /// 出差(小时)
        /// </summary>
        private static PropertyInfo< decimal > TripTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("TripTime"));
        [Column]
        public decimal TripTime
        {
            get { return GetProperty(TripTimeProperty); }
            set { SetProperty(TripTimeProperty, value); }
        }
		/// <summary>
        /// 工作日加班(单位小时h)
        /// </summary>
        private static PropertyInfo< decimal > WorkDayOverTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("WorkDayOverTime"));
        [Column]
        public decimal WorkDayOverTime
        {
            get { return GetProperty(WorkDayOverTimeProperty); }
            set { SetProperty(WorkDayOverTimeProperty, value); }
        }
		/// <summary>
        /// 周末加班(单位小时h)
        /// </summary>
        private static PropertyInfo< decimal > WeekendOverTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("WeekendOverTime"));
        [Column]
        public decimal WeekendOverTime
        {
            get { return GetProperty(WeekendOverTimeProperty); }
            set { SetProperty(WeekendOverTimeProperty, value); }
        }
		/// <summary>
        /// 节假日加班(单位小时h)
        /// </summary>
        private static PropertyInfo< decimal > HolidayOverTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("HolidayOverTime"));
        [Column]
        public decimal HolidayOverTime
        {
            get { return GetProperty(HolidayOverTimeProperty); }
            set { SetProperty(HolidayOverTimeProperty, value); }
        }
		/// <summary>
        /// 缺勤(单位小时h)
        /// </summary>
        private static PropertyInfo< decimal > AbsenceTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("AbsenceTime"));
        [Column]
        public decimal AbsenceTime
        {
            get { return GetProperty(AbsenceTimeProperty); }
            set { SetProperty(AbsenceTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > TiaoxiuTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("TiaoxiuTime"));
        [Column]
        public decimal TiaoxiuTime
        {
            get { return GetProperty(TiaoxiuTimeProperty); }
            set { SetProperty(TiaoxiuTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > BinJiaTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("BinJiaTime"));
        [Column]
        public decimal BinJiaTime
        {
            get { return GetProperty(BinJiaTimeProperty); }
            set { SetProperty(BinJiaTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > ShiJiaTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("ShiJiaTime"));
        [Column]
        public decimal ShiJiaTime
        {
            get { return GetProperty(ShiJiaTimeProperty); }
            set { SetProperty(ShiJiaTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > NianJiaTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("NianJiaTime"));
        [Column]
        public decimal NianJiaTime
        {
            get { return GetProperty(NianJiaTimeProperty); }
            set { SetProperty(NianJiaTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > HunJiaTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("HunJiaTime"));
        [Column]
        public decimal HunJiaTime
        {
            get { return GetProperty(HunJiaTimeProperty); }
            set { SetProperty(HunJiaTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > SangJiaTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("SangJiaTime"));
        [Column]
        public decimal SangJiaTime
        {
            get { return GetProperty(SangJiaTimeProperty); }
            set { SetProperty(SangJiaTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > ChanJiaTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("ChanJiaTime"));
        [Column]
        public decimal ChanJiaTime
        {
            get { return GetProperty(ChanJiaTimeProperty); }
            set { SetProperty(ChanJiaTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > ChanJianJiaTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("ChanJianJiaTime"));
        [Column]
        public decimal ChanJianJiaTime
        {
            get { return GetProperty(ChanJianJiaTimeProperty); }
            set { SetProperty(ChanJianJiaTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > PeiChanJiaTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("PeiChanJiaTime"));
        [Column]
        public decimal PeiChanJiaTime
        {
            get { return GetProperty(PeiChanJiaTimeProperty); }
            set { SetProperty(PeiChanJiaTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > GongshanJiaTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("GongshanJiaTime"));
        [Column]
        public decimal GongshanJiaTime
        {
            get { return GetProperty(GongshanJiaTimeProperty); }
            set { SetProperty(GongshanJiaTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > FaDingJiaTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("FaDingJiaTime"));
        [Column]
        public decimal FaDingJiaTime
        {
            get { return GetProperty(FaDingJiaTimeProperty); }
            set { SetProperty(FaDingJiaTimeProperty, value); }
        }
		/// <summary>
        /// 外出
        /// </summary>
        private static PropertyInfo< decimal > OutwardTimeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< decimal >("OutwardTime"));
        [Column]
        public decimal OutwardTime
        {
            get { return GetProperty(OutwardTimeProperty); }
            set { SetProperty(OutwardTimeProperty, value); }
        }
		/// <summary>
        /// 统计日期--指电脑统计的日期
        /// </summary>
        private static PropertyInfo< DateTime > StatDateProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< DateTime >("StatDate"));
        [Column]
        public DateTime StatDate
        {
            get { return GetProperty(StatDateProperty); }
            set { SetProperty(StatDateProperty, value); }
        }
		/// <summary>
        /// 是否确认过的，1-已确认，0-未确认
        /// </summary>
        private static PropertyInfo< string > IsValidateProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< string >("IsValidate"));
        [Column]
        public string IsValidate
        {
            get { return GetProperty(IsValidateProperty); }
            set { SetProperty(IsValidateProperty, value); }
        }

        /// <summary>
        /// 确认时间
        /// </summary>
        [Column]
        public string ValidateDate
        {
            get;
            set;
        }

		/// <summary>
        /// 是否被人工修改过，Y-修改过，N-未修改过，
        /// </summary>
        private static PropertyInfo< string > IsEditeProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< string >("IsEdite"));
        [Column]
        public string IsEdite
        {
            get { return GetProperty(IsEditeProperty); }
            set { SetProperty(IsEditeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< DateTime > EditDateProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< DateTime >("EditDate"));
        [Column]
        public DateTime EditDate
        {
            get { return GetProperty(EditDateProperty); }
            set { SetProperty(EditDateProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< Guid > EditWhoProperty = RegisterProperty(typeof(wkWorkResult),new PropertyInfo< Guid >("EditWho"));
        [Column]
        public Guid EditWho
        {
            get { return GetProperty(EditWhoProperty); }
            set { SetProperty(EditWhoProperty, value); }
        }

        /// <summary>
        /// 是否手工导入的结果,Y-是，N-否
        /// </summary>
        [Column]
        public string IsImport
        {
            get;
            set;
        }

        /// <summary>
        /// 手工导入的时间
        /// </summary>
        [Column]
        public string ImportDate
        {
            get;
            set;
        }

        #endregion
        
        #region Validation Rules 验证规则
        //将验证规则与业务对象的属性联系在一起
        protected override void AddBusinessRules()
        {
            //AddRule的第一个参数是委托变量，也就是说是方法的变量
            ValidationRules.AddRule(CommonRules.StringRequired, "WkStatus");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WkStatus", 100));
            ValidationRules.AddRule(CommonRules.StringRequired, "IsValidate");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("IsValidate", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "IsEdite");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("IsEdite", 10));
            //base.AddBusinessRules();
        }
        #endregion
        
        #region Factory Methods 工厂方法

        public wkWorkResult(){}

        public static wkWorkResult New()
        {
            return DataPortal.Create< wkWorkResult>();
        }
        public static wkWorkResult Get(Guid ID)
        {
            return DataPortal.Fetch< wkWorkResult>(new SingleLazyCriteria< wkWorkResult, Guid>(ID, false));
        }
        public static void Delete(Guid ID)
        {
            DataPortal.Delete(ID);
        }

        //public override wkWorkResult Save()
        //{
            //return base.Save();
        //}
        #endregion
		
		#region Data Access 数据访问
        //由于DataPortal_create中没有对数据库的访问，所有标记了Runlocal特性，使得该方法只需在本地运行即可
        //如果代码中有访问数据库的方法，那么就不要用这个特性，使数据门户可以根据情况将此方法的运行选择在应用服务器还是本地
        [RunLocal()]
        protected override void DataPortal_Create()
        {
            //在此调用CheckRules对所有的属性进行验证规则的检查，这样检查只运行一次。
            ValidationRules.CheckRules();
        }


        //可以看到此方法没有标记任何特性
        //此方法要访问数据库所以不能标记本地，由于她没有任何数据库更新操作所以也无需事务性的保护
        //此方法调用结束后会隐含的调用MarkOld（）方法
        private void DataPortal_Fetch(Guid ID)
        {
            //通过连接字符串建立SQL连接对象，Using符号代表，范围释放的意思，SqlConnection对象会在此范围后被释放掉
             using (var ctx = ConnectionManager<SqlConnection>.GetManager(ConnectionStringNames))
            {
                IDb db = DbFactory.Instance.GetDb(ctx.Connection);
                IQuery q = db.Query();
                q.Constrain("ID").Equal(ID);
                var data = db.Select< wkWorkResult>(q)[0];
                LoadProperty(IDProperty, data.ID);
                LoadProperty(EmployeeIDProperty, data.EmployeeID);
                LoadProperty(WorkDateProperty, data.WorkDate);
                LoadProperty(BeginCardDateTimeProperty, data.BeginCardDateTime);
                LoadProperty(EndCardDateTimeProperty, data.EndCardDateTime);
                LoadProperty(WorkTimeIDProperty, data.WorkTimeID);
                LoadProperty(WkStatusProperty, data.WkStatus);
                LoadProperty(LateTimeProperty, data.LateTime);
                LoadProperty(AdvancedTimeProperty, data.AdvancedTime);
                LoadProperty(LeaveTimeProperty, data.LeaveTime);
                LoadProperty(TripTimeProperty, data.TripTime);
                LoadProperty(WorkDayOverTimeProperty, data.WorkDayOverTime);
                LoadProperty(WeekendOverTimeProperty, data.WeekendOverTime);
                LoadProperty(HolidayOverTimeProperty, data.HolidayOverTime);
                LoadProperty(AbsenceTimeProperty, data.AbsenceTime);
                LoadProperty(TiaoxiuTimeProperty, data.TiaoxiuTime);
                LoadProperty(BinJiaTimeProperty, data.BinJiaTime);
                LoadProperty(ShiJiaTimeProperty, data.ShiJiaTime);
                LoadProperty(NianJiaTimeProperty, data.NianJiaTime);
                LoadProperty(HunJiaTimeProperty, data.HunJiaTime);
                LoadProperty(SangJiaTimeProperty, data.SangJiaTime);
                LoadProperty(ChanJiaTimeProperty, data.ChanJiaTime);
                LoadProperty(ChanJianJiaTimeProperty, data.ChanJianJiaTime);
                LoadProperty(PeiChanJiaTimeProperty, data.PeiChanJiaTime);
                LoadProperty(GongshanJiaTimeProperty, data.GongshanJiaTime);
                LoadProperty(FaDingJiaTimeProperty, data.FaDingJiaTime);
                LoadProperty(OutwardTimeProperty, data.OutwardTime);
                LoadProperty(StatDateProperty, data.StatDate);
                LoadProperty(IsValidateProperty, data.IsValidate);
                LoadProperty(IsEditeProperty, data.IsEdite);
                LoadProperty(EditDateProperty, data.EditDate);
                LoadProperty(EditWhoProperty, data.EditWho);
            }
        }

        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
            //依然是调用下面的方法删除的，只是他此时可以获得自己的Id
            DataPortal_Delete(IDProperty);
        }
        #endregion

	}
}

